package com.oracle.oa.action;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.oracle.oa.biz.MessageBiz;
import com.oracle.oa.biz.MessageToUserBiz;
import com.oracle.oa.biz.impl.MessageBizImpl;
import com.oracle.oa.biz.impl.MessageToUserBizImpl;
import com.oracle.oa.entity.Userinfo;

public class ShowNewMessageAction extends ActionSupport implements SessionAware {

	Map<String, Object> session;
	public String unread;

	MessageToUserBiz mtubiz;
	MessageBiz mbiz;
	
	public void setSession(Map<String, Object> arg0) {
		this.session = arg0;
	}

	/**
	 * 显示一共有多少条未读信息，在index页面实时刷新
	 * @return
	 */
	public String shownewmcount(){
		//显示有多少条未读信息
		Userinfo u = (Userinfo) session.get("userinfo"); 
		int unreadcount = mtubiz.getByTouseridAndIfread(u, 0L);
		if(unreadcount!=0){
			this.setUnread("您有"+unreadcount+"条未读消息");
		}
		
		return SUCCESS;
	}
	
	
	/**
	 * 显示一共有多少条未读信息，在信息页面刷新
	 * @return
	 */
	public String unreadcount(){
		//显示未读信息条数
		Userinfo u = (Userinfo) session.get("userinfo"); 
		int unreadcount = mtubiz.getByTouseridAndIfread(u, 0L);
		this.setUnread(unreadcount+"");
		return SUCCESS;
	}
	
	/**
	 * 显示收件箱总数，在信息页面刷新
	 * @return
	 */
	public String inboxcount(){
		//显示收件箱总数
		Userinfo u = (Userinfo) session.get("userinfo"); 
		int inboxcount=(Integer) mtubiz.getByUserid(u.getUserid());
		this.setUnread(inboxcount+"");
		return SUCCESS;
	}
	
	/**
	 * 显示草稿箱总数，在信息页面刷新
	 * @return
	 */
	public String unsendcount(){
		//未发送（草稿箱）总数
		Userinfo u = (Userinfo) session.get("userinfo"); 
		int unsendcount=mbiz.getByTouserAndIfpublish(u, 0L);
		this.setUnread(unsendcount+"");
		return SUCCESS;
	}
	
	/**
	 * 显示已发送总数，在信息页面刷新
	 * @return
	 */
	public String sendcount(){
		//已发送总数
		Userinfo u = (Userinfo) session.get("userinfo"); 
		int sendcount=mbiz.getByTouserAndIfpublish(u, 1L);
		this.setUnread(sendcount+"");
		return SUCCESS;
	}
	
	
	public String getUnread() {
		return unread;
	}

	public void setUnread(String unread) {
		this.unread = unread;
	}

	public MessageToUserBiz getMtubiz() {
		return mtubiz;
	}

	public void setMtubiz(MessageToUserBiz mtubiz) {
		this.mtubiz = mtubiz;
	}

	public MessageBiz getMbiz() {
		return mbiz;
	}

	public void setMbiz(MessageBiz mbiz) {
		this.mbiz = mbiz;
	}

}
